home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / listbox / tlsrc / treelist.bas < prev    next >
Encoding:
BASIC Source File  |  1994-10-30  |  4.2 KB  |  133 lines

  1. Option Explicit
  2.  
  3. Global NewLine              As String * 2
  4. Global tabs                 As String * 1
  5.  
  6. Type TreeListType
  7.     Caption                 As String
  8.     Number                  As Long
  9.     BranchType              As Integer
  10.     LeafDeep                As Integer
  11.     ShowBranches            As Integer
  12. End Type
  13. Dim TreeList()              As TreeListType
  14. 'Branchtypes
  15. Const btRoot = 1
  16. Const btBranch = 2
  17. Const btLeaf = 3
  18. 'AddLine
  19. Global Const alAdd = 1
  20. Global Const alCreate = 2
  21. Global Const alNew = 3
  22.  
  23. Sub tlAddLine (MyString As String, MyDeep As Integer, MyFlag As Integer, MyList As ListBox)
  24. Dim temp$
  25. Static MyText$
  26.     temp$ = String(MyDeep, Chr$(9))
  27.     Select Case MyFlag
  28.         Case alNew
  29.             MyText$ = MyString
  30.         Case alAdd
  31.             MyText$ = MyText$ + NewLine + temp$ + MyString
  32.         Case alCreate
  33.             MyText$ = MyText$ + NewLine + temp$ + MyString
  34.             tlCreate MyList, MyText$
  35.         Case Else
  36.     End Select
  37. End Sub
  38.  
  39. Sub tlCreate (MyList As ListBox, MyText As String)
  40. Dim cr As Integer, bd As Integer, b As Integer
  41. Dim i As Long, c As Long
  42. Dim temp$, branch$
  43.     temp$ = MyText
  44.     MyList.Clear
  45.     Do
  46.         cr = InStr(temp$, NewLine)
  47.         If cr Then
  48.             temp$ = Right$(temp$, Len(temp$) - cr)
  49.             c = c + 1
  50.         End If
  51.     Loop While cr
  52.     ReDim TreeList(c)
  53.     temp$ = MyText
  54.     For i = 0 To c
  55.         cr = InStr(temp$, NewLine)
  56.         If cr Then
  57.             branch$ = Left$(temp$, cr - 1)
  58.             temp$ = Right$(temp$, Len(temp$) - cr)
  59.         Else
  60.             branch$ = temp$
  61.         End If
  62.         If Len(branch$) Then
  63.             If Asc(branch$) = 10 Then branch$ = Right$(branch$, Len(branch$) - 1)
  64.             bd = 0
  65.             TreeList(i).Caption = branch$
  66.             TreeList(i).Number = i
  67.             TreeList(i).ShowBranches = False
  68.             Do
  69.                 b = InStr(branch$, tabs)
  70.                 If b Then
  71.                     bd = bd + 1
  72.                     branch$ = Right$(branch$, Len(branch$) - b)
  73.                 End If
  74.             Loop While b
  75.             If bd = 0 Then
  76.                 TreeList(i).BranchType = btRoot
  77.                 MyList.AddItem TreeList(i).Caption
  78.                 MyList.ItemData(MyList.NewIndex) = i
  79.             Else
  80.                 TreeList(i).BranchType = btLeaf
  81.             End If
  82.             TreeList(i).LeafDeep = bd
  83.             If i > 0 Then
  84.                 If TreeList(i).LeafDeep > TreeList(i - 1).LeafDeep Then
  85.                     TreeList(i - 1).BranchType = btBranch
  86.                 End If
  87.             End If
  88.         End If
  89.     Next i
  90.     TreeList(i - 1).BranchType = btLeaf
  91. End Sub
  92.  
  93. Function tlDblClick (MyList As ListBox) As Integer
  94. Dim ti As Long, b As Long, li As Long, i As Long, sbi As Integer
  95.     tlDblClick = False
  96.     li = MyList.ListIndex
  97.     ti = MyList.ItemData(li)
  98.     Select Case TreeList(ti).BranchType
  99.         Case btRoot, btBranch
  100.             If TreeList(ti).ShowBranches Then
  101.                 li = li + 1
  102.                 For i = li To MyList.ListCount - 1
  103.                     sbi = MyList.ItemData(li)
  104.                     If TreeList(ti).LeafDeep < TreeList(sbi).LeafDeep Then
  105.                         TreeList(sbi).ShowBranches = False
  106.                         MyList.RemoveItem li
  107.                     Else
  108.                         Exit For
  109.                     End If
  110.                 Next i
  111.                 TreeList(ti).ShowBranches = False
  112.             Else
  113.                 b = ti + 1
  114.                 For i = b To UBound(TreeList)
  115.                     If TreeList(ti).LeafDeep < TreeList(i).LeafDeep Then
  116.                         If TreeList(ti).LeafDeep + 1 = TreeList(i).LeafDeep Then
  117.                             li = li + 1
  118.                             MyList.AddItem TreeList(i).Caption, li
  119.                             MyList.ItemData(MyList.NewIndex) = i
  120.                         End If
  121.                     Else
  122.                         Exit For
  123.                     End If
  124.                 Next i
  125.                 TreeList(ti).ShowBranches = True
  126.             End If
  127.         Case btLeaf
  128.             tlDblClick = True
  129.         Case Else
  130.     End Select
  131. End Function
  132.  
  133.